package com.cisetech.web.bobocai.houtai;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.jdbc.util.Login;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cisetech.job.AccessTokenJob;
import com.cisetech.service.AdvService;
import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.LBanner;

//轮播图设置
@Controller
@RequestMapping(value="/ht/adv")
public class AdvController{
	
	private final static Logger log = LoggerFactory.getLogger(AccessTokenJob.class);
	
	@Autowired
	AdvService advService;
	
	@RequestMapping(value="",method=RequestMethod.GET)
	public ModelAndView index(HttpServletResponse response,HttpServletRequest request){
		
		ModelAndView v = new ModelAndView("houtai/adv");
		return v;
	}
	//跳转添加或修改页面
	@RequestMapping(value="/addadv",method=RequestMethod.GET)
	public ModelAndView addadv(HttpServletResponse response,HttpServletRequest request){
		
		ModelAndView v = new ModelAndView("houtai/addadv");
		return v;
	}
	@ResponseBody
	@RequestMapping(value="/banner",method=RequestMethod.POST)
	public String image(LBanner banner,HttpServletRequest request,HttpServletResponse response){
		int i = advService.insertAdv(banner);
		return i+"";
	}
	@ResponseBody
	@RequestMapping(value="/getList",method=RequestMethod.POST)
	public Page<LBanner> getListAdv(LBanner banner,HttpServletRequest request,HttpServletResponse response){
		Page<LBanner> page = advService.getListAdv(banner);
		return page;
	}
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String  deleteAdv(String id,HttpServletRequest request,HttpServletResponse response){
		int i = advService.deleteAdv(id);
		System.out.println(i);
		return i+"";
	}
	//根据id查询banner
	@RequestMapping(value="/updateAdv",method=RequestMethod.GET)
	public ModelAndView  FindListByAdv(LBanner banner,HttpServletRequest request,HttpServletResponse response){
		ModelAndView v = new ModelAndView("houtai/addadv");
		try {
			List<LBanner> list = advService.FindListByAdv(banner);
			if(list!=null && list.size()>0){
				v.addObject("type", "0");
				v.addObject("banner", list.get(0));
			}
		} catch (Exception e) {
			v.addObject("type", "1");
			log.debug(e.getLocalizedMessage());
		}
		return v;
	}
}
